package sort;

import java.util.Arrays;

/**快速排序*/
public class QuickSort {
    public static void main(String[] args) {
        int [] arr = {5,8,3,4,1,9,6,7,2,0};
        sort(arr);
        System.out.println(Arrays.toString(arr));
    }

    private static void sort(int [] arr) {
        sort(arr,0,arr.length-1);
    }

    private static void sort(int[] arr, int left, int right) {
        if(left>=right){
            return;
        }
        int base = arr[left];
        int i = left;
        int j = right;
        while (i<j){
            while (i<j && arr[j]>=base) {
                j--;
            }
            arr[i]=arr[j];
            while ( i <j && arr[i]<=base ) {
                i++;
            }
            arr[j]=arr[i];
        }
        arr[i]=base;
        sort(arr,left,i-1);
        sort(arr,i+1,right);
    }
}
